package edu.pku.sei.transformation.editor.controller.policies;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.ReconnectRequest;

import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.transformation.editor.controller.commands.CommandFactory;
import edu.pku.sei.transformation.editor.controller.commands.link.LinkCreateCommand;

public class TransformationNodeEditPolicy extends GraphicalNodeEditPolicy {

	@Override
	protected Command getConnectionCompleteCommand(
			CreateConnectionRequest request) {
		MetaNode targetNode = (MetaNode) this.getHost().getModel();
		LinkCreateCommand cmd = (LinkCreateCommand) request.getStartCommand();

		cmd = CommandFactory.completeCreateCommand(cmd, targetNode);

		return cmd;
	}

	@Override
	protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
		MetaLink connectionLink = (MetaLink) request.getNewObject();
		MetaNode sourceNode = (MetaNode) this.getHost().getModel();

		LinkCreateCommand cmd = CommandFactory.getCreateCommand(connectionLink,
				sourceNode);
		request.setStartCommand(cmd);
		return cmd;
	}

	@Override
	protected Command getReconnectSourceCommand(ReconnectRequest request) {
		return null;
	}

	@Override
	protected Command getReconnectTargetCommand(ReconnectRequest request) {
		return null;
	}

}
